package com.nvn.androidapp.Objects;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;

import com.nvn.androidapp.R;
import com.nvn.androidapp.adapters.MenuAdapter;
import com.nvn.androidapp.utils.Statics;

public class MenuDialog extends Dialog{
	/*
	 * private fields
	 */
	private Activity context;
	private LayoutInflater li;
	private View v;
	private ImageView imv_close;
	private OnOkClickListener onOk;
	private GridView grid_menu;
	private ArrayList<ItemMenu> items;
	private MenuAdapter mAdapter;
	/*
	 * constructor
	 */
	public MenuDialog(Activity context) {
		super(context, R.style.style_dialog);
		this.context = context;
		init();

		this.setContentView(v);
		this.setCancelable(false);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
		this.getWindow().setLayout(Statics.PixelFromDp(context, 290), Statics.PixelFromDp(context, 260));
	}

	/*
	 * initialize method
	 */
	private void init() {
		li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		v = li.inflate(R.layout.layout_menu, null);
		
		
		imv_close = (ImageView)v.findViewById(R.id.imv_close);
		imv_close.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dismiss();
			}
		});
		
		items = new ArrayList<ItemMenu>();
		items.add(new ItemMenu(R.drawable.ic_sale, "Sale"));
		for(int i=0; i<29; i++){
			items.add(new ItemMenu(R.drawable.ic_star, "Other"));
		}
		
		mAdapter = new MenuAdapter(context, items);
		
		grid_menu = (GridView)v.findViewById(R.id.grid_menu);
		
		mAdapter.setOnOkClickListener(new MenuAdapter.OnOkClickListener() {
			
			@Override
			public void onOkClick(String txt) {
				dismiss();
				if(null != onOk) onOk.onOkClick(txt);
			}
		});
		

		grid_menu.setNumColumns(3);
		
		grid_menu.setAdapter(mAdapter);
		
	}


	public void setOnOkClickListener(OnOkClickListener onOk){
		this.onOk = onOk;
	}
	
	public interface OnOkClickListener{
		public void onOkClick(String txt);
	}
	
	public void show() {
		super.show();
	}

}
